<template>
  <div class="question-detail-box">
    <div class="question-detail-nav">
      <my-top-nav :title="'答题详情'" @clickBack="clickBack"></my-top-nav>
    </div>
    <div class="question-detail-content">
      <div class="question-detail-header">
        <div class="question-detail-header-title">错题明细</div>
        <div class="question-detail-header-statistics">
          <div class="statistics-correct">
            <div class="statistics-correct-msg">正确数</div>
            <div class="statistics-correct-num">{{questionCorrectNum}}</div>
          </div>
          <div class="statistics-error">
            <div class="statistics-error-msg">错误数</div>
            <div class="statistics-error-num">{{questionErrorNum}}</div>
          </div>
        </div>
      </div>
      <div class="question-detail-body">
        <div class="question-detail-item" v-for="(item,index) in answerDatalist" :key="index">
          <div class="question-detail-item-title">{{item.systemTitle}}</div>
          <div class="question-detail-item-user-answer">
            <div class="item-user-error-answer" v-if="item.userAnswerType === '错误'">
              <div class="item-user-error-btn">
                <img class="item-user-error-icon" src="../../assets/search/errorIcon.png" alt="">
                {{item.userAnswer}}</div>
              <div class="item-user-error-desc">{{item.userAnswerType}}</div>
            </div>
            <div class="item-user-correct-answer" v-else-if="item.userAnswerType === '正确'">
              <div class="item-user-correct-btn">
                <img class="item-user-correct-icon" src="../../assets/search/correctIcon.png" alt="">
                {{item.userAnswer}}</div>
              <div class="item-user-correct-desc">{{item.userAnswerType}}</div>
            </div>
          </div>
          <div class="question-detail-item-system">
            <div class="question-detail-item-system-btn">
              <img class="item-system-icon" src="../../assets/search/correctIcon.png" alt="">
              {{item.systemAnswer}}</div>
            <div class="question-detail-item-system-desc">{{item.systemAnswerType}}</div>
          </div>
          <div class="item-user-empty-answer" v-if="item.userAnswerType === '未作答'">
            <img src="../../assets/search/未作答.png" alt="">
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import myTopNav from "../../components/myTopNav";

export default {
  data() {
    return {
      answerDatalist: [], // 答题详情数组
      questionCorrectNum: 0, // 正确数
      questionErrorNum: 0 // 错误数
    };
  },
  components: {
    myTopNav
  },
  mounted() {
    console.log("我是route", this.$route);
    if (this.$route.query.answerList && this.$route.query.querstionList) {
      this.valiteData(
        this.$route.query.answerList,
        this.$route.query.querstionList
      );
    }
  },
  methods: {
    /**
     * @author: 张志名 [1372342958@qq.com]
     * @description: 判断答题情况，封装数据
     * @param {type} {Object}
     * @return: {void}
     * @Date: 2019-12-19 08:49:58
     */
    valiteData(userAnswer, systemQuestion) {
      for (var i = 0, j = systemQuestion.length; i < j; i++) {
        let obj = {};
        obj.systemTitle = `${systemQuestion[i].title}属于什么垃圾`;
        obj.systemAnswer = systemQuestion[i].classification;
        obj.systemAnswerType = "正确";
        if (userAnswer[i] != "") {
          if (userAnswer[i] === systemQuestion[i].classification) {
            obj.userAnswer = userAnswer[i];
            obj.userAnswerType = "正确";
            this.questionCorrectNum++;
          } else {
            obj.userAnswer = userAnswer[i];
            obj.userAnswerType = "错误";
            this.questionErrorNum++;
          }
        } else {
          obj.userAswer = "未作答";
          obj.userAnswerType = "未作答";
          this.questionErrorNum++;
        }
        this.answerDatalist.push(obj);
      }
      console.log("我是封装的数据  ", this.answerDatalist);
    },
    /**
     * @author: 张志名 [1372342958@qq.com]
     * @description: 返回
     * @param {type} {Object}
     * @return: {void}
     * @Date: 2019-12-18 19:56:11
     */
    clickBack() {
      this.$router.back();
    }
  }
};
</script>

<style lang="scss" scoped>
.question-detail-box {
  background-color: rgb(19, 4, 95);
  .question-detail-content {
    padding: 80px 6%;
    padding-bottom: 0;
  }
  .question-detail-header {
    background-color: rgb(89, 97, 222);
    height: 100px;
    border-radius: 8px;
    box-shadow: 0px 10px 10px 0px rgba(148, 174, 191, 0.3);
    color: #ffffff;
    padding-top: 10px;
    font-weight: 700;
    font-size: 16px;
    .question-detail-header-title {
      text-align: center;
    }
    .question-detail-header-statistics {
      display: flex;
      justify-content: space-around;
      align-items: center;
      .statistics-correct {
        display: flex;
        flex-direction: column;
        align-items: center;
        .statistics-correct-num {
          margin-top: 10px;
        }
      }
      .statistics-error {
        display: flex;
        flex-direction: column;
        align-items: center;
        .statistics-error-num {
          margin-top: 10px;
        }
      }
    }
  }
  .question-detail-body {
    margin-top: 20px;
    padding-bottom: 20px;
    .question-detail-item {
      background-color: #ffffff;
      // height: 200px;
      border-radius: 8px;
      padding: 20px 20px;
      padding-bottom: 10px;
      margin: 20px 0;
      box-sizing: border-box;
      display: flex;
      justify-content: space-around;
      flex-direction: column;
      font-weight: 700;
      font-family: "微软雅黑";
      position: relative;
      .item-user-empty-answer {
        position: absolute;
        top: 3px;
        right: 3px;
        img {
          width: 60px;
          height: 60px;
        }
      }
      .question-detail-item-user-answer {
        box-sizing: border-box;
        margin-top: 20px;
        .item-user-error-answer {
          display: flex;
          justify-content: flex-start;
          align-items: center;
          height: 40px;
          .item-user-error-btn {
            background-color: rgb(254, 92, 90);
            width: 70%;
            height: 40px;
            border-radius: 50px;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #ffffff;
            margin-right: 40px;
            box-sizing: border-box;
            position: relative;
            .item-user-error-icon {
              width: 20px;
              height: 20px;
              position: absolute;
              left: 20px;
              top: 10px;
            }
          }
          .item-user-error-desc {
            color: rgb(254, 92, 90);
            font-size: 16px;
          }
        }
        .item-user-correct-answer {
          display: flex;
          justify-content: flex-start;
          align-items: center;
          height: 40px;
          .item-user-correct-btn {
            background-color: rgb(45, 223, 147);
            width: 70%;
            height: 40px;
            border-radius: 50px;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #ffffff;
            margin-right: 40px;
            box-sizing: border-box;
            position: relative;
            .item-user-correct-icon {
              width: 20px;
              height: 20px;
              position: absolute;
              left: 20px;
              top: 10px;
            }
          }
          .item-user-correct-desc {
            color: rgb(45, 223, 147);
            font-size: 16px;
          }
        }
      }
      .question-detail-item-system {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        box-sizing: border-box;
        margin-top: 20px;
        .question-detail-item-system-btn {
          background-color: rgb(45, 223, 147);
          width: 70%;
          height: 40px;
          border-radius: 50px;
          display: flex;
          justify-content: center;
          align-items: center;
          color: #ffffff;
          margin-right: 40px;
          box-sizing: border-box;
          position: relative;
          .item-system-icon {
            width: 20px;
            height: 20px;
            position: absolute;
            left: 20px;
            top: 10px;
          }
        }
        .question-detail-item-system-desc {
          color: rgb(45, 223, 147);
          font-size: 16px;
        }
      }
    }
  }
}
</style>
<style lang="scss">
.question-detail-box {
  .question-detail-nav {
    position: fixed;
    top: 0px;
    left: 0px;
    width: 100%;
    z-index: 10;
    .van-nav-bar {
      background-color: rgb(19, 4, 95);
    }
    .van-nav-bar__title {
      color: #ffffff;
    }
    .van-icon {
      color: #ffffff;
    }
    .van-nav-bar__arrow {
      color: #ffffff;
    }
    .van-hairline--bottom::after {
      border-bottom: none;
    }
    .van-nav-bar__text {
      color: #ffffff;
    }
  }
}
</style>
